Fix nargs=REMAINDER and empty value issues (#285, #296)#342
Open
Fix nargs=REMAINDER and empty value issues (#285, #296)#342
Conversation
- Fix issue #285: nargs=REMAINDER breaking config file parsing * When no optional args exist on command line, check if any positional arg uses REMAINDER * If REMAINDER exists, prepend config/env args to avoid consumption * Otherwise, append to end (original behavior) to avoid nargs="+" consuming positional args * Add testRemainderWithConfigFile() regression test - Fix issue #296: Empty env var and empty YAML key behave differently * Skip empty string values for args with nargs in both config files and env vars * This matches YAML behavior where empty values are treated as None * Preserves empty strings for simple args without nargs * Add testEmptyValuesIgnored() regression test Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two medium-term issues:
nargs=argparse.REMAINDERcan break config file option parsing #285: nargs=REMAINDER breaking config file parsingChanges
Fix for nargs=REMAINDER (#285)
When a positional argument uses
nargs=argparse.REMAINDER, it consumes all remaining arguments. The previous logic would append config/env args to the end of the command line when no optional args were present, causing REMAINDER to consume them incorrectly.Solution: Check if any positional argument uses REMAINDER:
Fix for empty values (#296)
Empty environment variables and empty YAML keys were behaving inconsistently. YAML returns
Nonefor empty values (treated as missing), but env vars and config files were passing empty strings through.Solution: Skip empty string values for args with
nargsin both config file and env var processing. This matches YAML behavior while preserving empty strings for simple args without nargs.Tests
testRemainderWithConfigFile()regression test for issuenargs=argparse.REMAINDERcan break config file option parsing #285testEmptyValuesIgnored()regression test for issue Empty environment variable and empty yaml key behave differently #296Related
nargs=argparse.REMAINDERcan break config file option parsing #285